module.exports = class extends think.cmswing.rest {
	
   /**
   * 获取分类信息
   * /api/shop 获取全部代理
   * /api/shop/1 获取代理id为1的栏目信息
   * @returns {Promise.<*>}
   */
	
  async getAction() {
   const cmd = this.get('cmd') || '';
   const type = this.get('type') || '';
   const map = {
           status: 1,
           model_id:4,
           type:1
   };
   let goods = [];
   let list = await this.model('document').where(map).order('update_time desc').field('id,title,type,category_id,pics,price,update_time').select();
   for (const val of list) {
	 let good = {id:0,title:'',price:0,num:0,type:''};
	 let goods_no = await this.model('document_shop').where({id:val.id}).getField('goods_no', true);
	 const goodnos = goods_no.split('_');
	 if(!think.isEmpty(type)){
		 if(type==goodnos[0]){
			 good.id = val.id;
			 good.title = val.title;
		  	 good.price = formatCurrency(get_price(val.price, 1));
		  	 good.num = goodnos[1];
		  	 good.type = goodnos[0];
		  	 goods.push(good); 
		 }
	 }else{
		 good.id = val.id;
		 good.title = val.title;
	  	 good.price = formatCurrency(get_price(val.price, 1));
	  	 good.num = goodnos[1];
	  	 good.type = goodnos[0];
	  	 goods.push(good);
	 }
  }
   //const totalid = await this.model('member').where({username: this.id,status:1,is_admin:0}).count('id');
   if(goods.length>0){
	   return this.success(goods);
   }else{
	   return this.fail('商品信息不存在！');
   }
  }
  
  async postAction() {
	const data = this.post();
	console.log('shop post action-data--------:'+JSON.stringify(data));
    return this.success({name:'post成功！'});
  }
  //数据状态0禁用，1启用，-1删除
};
